Template comparison analysis is a very important machine vision algorithm, and has been extensively described both in the patent literature and in text books. Essentially the process uses machine vision techniques to determine areas of difference between a digitally stored version of a known good image of an is object, and an image of what is supposed to be an identical object often taken directly on the production line. Its primary purpose is to automatically identify a flawed or damaged product, by "recognizing" a blemish in a sample image.
The current methodology often generates a reference or mean template image by "averaging" the image information (i.e. reference images) from several known good objects in order to increase the signal-to-noise ratio. As the mean template image is obtained by combining the data on a per pixel basis, it is essential that the relative alignment of the object and the camera be kept rigorously consistent; else subsequent images must be adjusted for alignment prior to being added to the average image.
In order to minimize the effects of areas that are known to be noise prone, even after alignment, many systems also derive a standard deviation image (i.e., .sigma. image) or a variation image. These images essentially map the high variance regions of the template. The standard deviation image can be used to generate a mask image which flags areas of the sample image where it is unwise to undertake pixel comparison.
Once the reference or template image has been trained, it is used by undertaking a pixel aligned absolute subtraction between the template and the incoming sample image. In an ideal world, the pixels of the sample image would all be identical to those in the template image. However, in practice, even in areas where there has been no change, noise will ensure that the intensity levels of the template and the sample image will be slightly different. Areas containing a major blemish will result in a very large difference signal being generated. The absolute operator ensures that any difference signal is always positive, and the resulting error map can be treated exactly as an image. Areas of difference that occur within high variation regions indicated by a set mask image pixel are set to zero, and are consequently ignored.
The process of comparison simply undertakes the absolute subtraction between the mean image and the sample image, and the result is masked by a thresholded version of the standard deviation or variation image.
Referring now to FIG. 1, one technique of U.S. Pat. No. 5,640,200 initially creates a composite template image by statistically combining multiple instances of a "perfect" image. The resulting template consists of a mean image, together with a standard deviation image (i.e. .sigma. image). Naturally, the areas of most "rapid" rate of change within the template components (i.e. edges and regions of color change) provide most of the contribution to the standard deviation image, which can be used to form a mask of regions which, even on a good sample, are subject to the greatest variation, and, on hunting for flaws, can be given much less weight than areas that are subject to little change.
Once the template image has been fully trained, sample images taken from the production line can be compared with it. However, there is very little chance of the template and sample image exactly overlaying. In order to remove this misalignment some form of registration must be undertaken. This process invariably uses some form of correlation between either known landmarks or fiducial marks on both template and sample images, else using the complete image itself. Done properly, this process can provide a sub-pixel accurate measurement of the relative positioning of the template and the sample. This information can be used to either digitally re-register the images, or else can be used to re-position the sample image relative to the camera to ensure that the two images are optimally aligned.
Flaws between the template image and the sample image can then be detected by the simple process of undertaking an absolute subtraction of the two. Thus, any difference, irrespective of whether the intensity is brighter or darker than the other, results in a positive difference.
The value of this difference can either be thresholded, or else compared to the standard deviation image. Comparing with the a image allows one to determine if the difference in that region of the image is greater than that expected from the distribution derived from the template samples. If so, the pixel is marked as a flaw, or else it is considered as part of the natural statistical variation between acceptable samples. The resulting flaw flag can be directly used to provide an error image, which, after further analysis using morphological tools such as blob analysis, high-lights the position of any artifacts.
The system of the above-noted patent works well in many applications, and is used extensively. Although this technique is fairly rapid, it leaves a lot to be desired. For example, at what level does one threshold the deviation image to generate the mask image. Also, what level does one threshold the masked difference image to generate the error map. Too high a value and crucial errors will be missed, too low a value and minor differences due to noise will be included.